// *************************************************************************************************
//
// MK3D Engine
// --------------------------------------
// Copyright (C) 2007-2011 Zeb (mailto: zebbey@gmail.com)
//
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//
// *************************************************************************************************
#ifndef __H_MK_SKELETON_DATA__
#define __H_MK_SKELETON_DATA__

#include "mk_resource.h"
#include "mk_memory_block.h"

namespace MK3DE
{
	class MK3DE_API CSkeletonData : public CResource
	{
	public:
		CSkeletonData(const char* fileName);
		~CSkeletonData();

		RESOURCE_TYPE GetType() { return RES_T_SKELETON_DATA; }

		BOOL Load();

		std::string GetName() { return std::string(_header->name); }
		DWORD GetFrameCount() { return _header->frameNum; }
		BOOL IsRelative() { return _header->relative; }
		DWORD GetBoneCount() { return (DWORD)_header->boneNum; }

		BOOL GetBoneName(DWORD boneIdx, std::string& name);
		BOOL GetParentIdx(DWORD boneIdx, WORD& parentIdx);

		BOOL GetTranslationKey(DWORD boneIdx, DWORD keyIdx, D3DXVECTOR3& translation, BOOL& animation);
		BOOL GetRotationKey(DWORD boneIdx, DWORD keyIdx, D3DXQUATERNION& rotation, BOOL& animation);
		BOOL GetScaleKey(DWORD boneIdx, DWORD keyIdx, D3DXVECTOR3& scale, BOOL& animation);
		BOOL GetScaleRotationKey(DWORD boneIdx, DWORD keyIdx, D3DXQUATERNION& scaleRotation, BOOL& animation);

	private:
		void __Clean();

	public:
		struct Header
		{
			DWORD id;
			WORD version;
			WORD dumy;
			char name[31];
			BYTE relative;
			WORD frameNum;
			WORD boneNum;
			DWORD offsetBoneData;
			BYTE reserve[16];
		};

		struct BoneHeader
		{
			char name[32];
			WORD parentIdx;
			WORD translationNum;
			WORD rotationNum;
			WORD scaleNum;
			WORD scaleRotationNum;
			WORD dumy;
			DWORD offsetTranslation;
			DWORD offsetRotation;
			DWORD offsetScale;
			DWORD offsetScaleRotation;
			BYTE reserve[4];
		};

		static const FOURCC MK_SKELETON_ID = MAKEFOURCC('M', 'K', 'S', 'K');
		static const WORD MK_SKELETON_VER = MAKEWORD(1, 0);

	private:
		CMemoryBlock _dataBlock;
		Header* _header;
		BoneHeader* _boneHeaders;
	};
}

#endif // __H_MK_SKELETON_DATA__